Test if char is '0'-'9' [migrated]
Posted
by
Chris Okyen
on Programmers
See other posts from Programmers
or by Chris Okyen
Published on 2012-09-26T05:28:02Z
Indexed on
2012/09/26
9:51 UTC
Read the original article
Hit count: 172
My Java code is
// if the first character is not 0-9
if(
(((input.substring(0,0)).compareTo("1")) < 0 || (((input.substring(0,0)).compareTo("9")) < 0));
{
System.out.println("Error: The first digit of the temperature is not 1-9. Force Exiting Program. ");
System.exit(1); // exit the program
}
But it slips through even with input like '1123' or '912' or '222', and gives this error message. Whether I have it > 0 for first and < 0 for the second, or > 0 and > 0, or < 0 and < 0, or even < o and > 0... How come?
© Programmers or respective owner